//// GMeter.h /////////////////////////////////////////////////////////////////////////////
//
//  This is a graphical VU meter much like what you see on a digital equalizer.
//  You may create a meter and Hit it on a 100% scale (1 - 100).
//  The Timer will create an animated peak falloff if desired.
//
//  The control will draw a meter from green to red.
// 
//  Bugs:
//		The wxMemoryDc sometimes crashes. Expecially when threads fight over GMeter::Hit()
//
//  Todo:
//		We need a way to start and stop the global timer when we want to enable/diable meters.
//
///////////////////////////////////////////////////////////////////////////////////////////

#ifndef GMETER_H
#define GMETER_H

#include <wx/window.h>
#include <wx/panel.h>
#include <wx/dcbuffer.h> 
#include <wx/msgdlg.h>
#include <wx/stopwatch.h>
#include <wx/timer.h>
#include <wx/thread.h>

///////////////////////////////
class GMeter: public wxPanel
{ 

public: 

	GMeter(wxWindow* parent, wxWindowID id,	const wxPoint& pos, const wxSize& size, bool falloff); 
	~GMeter(); 

	bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size); 
    void OnMouse(wxMouseEvent &event);
	void OnPaint(wxPaintEvent &WXUNUSED(event));
	void Hit(int val);

    //Settings
	int SPEED1;
	int SPEED2;
	bool PEAK;
	int SPACING;

	wxSize mySize;

	int value;
	int falloff;
	
	wxStopWatch sw;
	long temp;
	long temp2;
	int falltemp;
	int peakfall;

	wxColour hitColor;
	wxColour peakcolor;
	wxCoord hitX1;
	wxCoord hitY1;
	wxCoord hitX2;
	wxCoord hitY2;
	
	wxMemoryDC *memDC;
	wxCriticalSection critical;
	wxClientDC *cdc2;
	
	bool eraseFlag;
	bool hitFlag;

	DECLARE_EVENT_TABLE();

};


////////////////////////////
class GTimer: public wxTimer
{
public:

	GTimer();

	int meters;
	GMeter *m_pointers[100];
    void AddMeter(GMeter &m_pointer);
	void Notify();
};

#endif //GMeter_H
